package com.gdssoft.pdaweb.service.water.impl;

/*
 *  捷达世软件（深圳）有限公司
 *  Copyright (C) 2008-2010 ShenZhen JieDaShi Software Limited Company.
 */
import java.util.List;

import com.gdssoft.core.service.impl.BaseServiceImpl;
import com.gdssoft.framework.model.system.AppUser;
import com.gdssoft.pdaweb.dao.water.PdaWaterMeterDao;
import com.gdssoft.pdaweb.model.water.PdaWaterMeter;
import com.gdssoft.pdaweb.service.water.PdaWaterMeterService;

public class PdaWaterMeterServiceImpl extends BaseServiceImpl<PdaWaterMeter>
		implements PdaWaterMeterService {
	private PdaWaterMeterDao dao;

	public PdaWaterMeterServiceImpl(PdaWaterMeterDao dao) {
		super(dao);
		this.dao = dao;
	}

	@Override
	public List<PdaWaterMeter> getAllForExcel() {
		return dao.getAllForExcel();
	}
	
	@Override
	public List<PdaWaterMeter> getWaterMeterExcel(String idS) {
		return dao.getWaterMeterExcel(idS);
	}

	@Override
	public PdaWaterMeter getByMeterId(String meterId) {
		return dao.getByMeterId(meterId);
	}

	@Override
	public boolean isExist(String amId) {
		return this.getByMeterId(amId).getAmId() == null ? false : true;
	}

	@Override
	public List<PdaWaterMeter> getWaterMeter(String districtId,
			String buildingId) {

		return dao.getByPosition(districtId, buildingId);
	}

	@Override
	public void changePlan(String choose, String selecteds) {
		String[] amChoose = {};
		String[] amSelected = {};
		if (choose.endsWith(",")) {
			amChoose = choose.substring(0, choose.length() - 1).split("[,]");
		}

		if (selecteds.endsWith(",")) {
			amSelected = selecteds.substring(0, choose.length() - 1).split(
					"[,]");
		}
		PdaWaterMeter pdaWaterMeter = new PdaWaterMeter();
		for (String amId : amChoose) {
			pdaWaterMeter.setAmId(amId);
			pdaWaterMeter.setIsPlanned("N");
			dao.save(pdaWaterMeter);
		}

		for (String amId : amSelected) {
			pdaWaterMeter.setAmId(amId);
			pdaWaterMeter.setIsPlanned("Y");
			dao.save(pdaWaterMeter);
		}
	}

	@Override
	public boolean isCrmMeterNoExist(String crmMeterNo) {
		return dao.isCrmMeterNoExist(crmMeterNo);
	}

	@Override
	public List<PdaWaterMeter> getSelectWaterMeter(String districtId,
			String[] ids) {
		// TODO Auto-generated method stub
		return dao.getSelectWaterMeter(districtId, ids);
	}

	@Override
	public boolean pauseAndResume(String recId, String vType, AppUser appUser,
			String dateT) {
		// TODO Auto-generated method stub
		// TODO Auto-generated method stub
		if (vType.equals("2")) {
			vType = "4";
		} else {
			vType = "2";
		}
		return dao.pauseAndResume(recId, vType, appUser, dateT);
	}

}